# StrangeCalculator.py # # Description: This program that takes a string as an input, # such as “24 + 16”, “30 – 5”, “10 * 4”, 36 // 2”, # computes the equation found in the string and # outputs the equation and its result such as # 24 + 16 = 40 # # Author: Anne Lavergne # Date: Feb. 28 2024 def performOpOnList(anOperandList, anOperation): """Returns the result of performing "anOperation" on the operands contained in "anOperandList". Returns 0 if 'anOperation' is not '+','-','*' or '//'.""" # Set result to 0 in case "anOperation" is not '+','-','*' or '//' result = 0 # Figure out which operation to perform on the operands if anOperation == "+": # Add both operands result = anOperandList[0] + anOperandList[1] elif anOperation == "-": # Subtract anOperand2 from anOperand1 result = anOperandList[0] - anOperandList[1] elif anOperation == "*": # Multiply both operands result = anOperandList[0] * anOperandList[1] elif anOperation == "//": # Divide anOperandList[0] by anOperandList[1] result = anOperandList[0] // anOperandList[1] else: result = "None" # Once done, return the result produced by this function # or "0" if anOperation was not '+','-','*' or '//'. return result #*** Main part of my program # Create a list theEquation = input("Please, enter an equation: ") equationList = theEquation.split() operandList = [] operandList.append(int(equationList[0])) operandList.append(int(equationList[2])) anOperation = equationList[1] theResult = performOpOnList(operandList, anOperation) if theResult == "None" : print(f"{anOperation} is an invalid operation (not '+','-','*' or '//').") else: print(f"{operandList[0]} {anOperation} {operandList[1]} = {theResult}")